import SwiftUI
import WidgetKit
import CalendarShared
import AppIntents

public struct SmallMonthView: View {
    @Environment(\.widgetFamily) var family
    @Environment(\.colorScheme) var colorScheme
    public let entry: LargeEntry
    public let todayIntent: (any AppIntent)?
    public let lastIntent: (any AppIntent)?
    public let nextIntent: (any AppIntent)?

    public init(entry: LargeEntry, todayIntent: (any AppIntent)? = nil, lastIntent: (any AppIntent)? = nil, nextIntent: (any AppIntent)? = nil) {
        self.entry = entry
        self.todayIntent = todayIntent
        self.lastIntent = lastIntent
        self.nextIntent = nextIntent
    }

    public var body: some View {
        switch family {
        case .systemSmall:
            MonthView(style: .small(todayIntent, lastIntent, nextIntent), entry: entry)
                .widgetBackground(entry.background.color(colorScheme))
        case .systemMedium:
            HStack {
                DayView(style: .date(entry))
                MonthView(style: .small(todayIntent, lastIntent, nextIntent), entry: entry)
            }
            .widgetBackground(entry.background.color(colorScheme))
        default:
            MonthView(style: .large(todayIntent, lastIntent, nextIntent), entry: entry)
                .widgetBackground(entry.background.color(colorScheme))
        }
    }
}
